﻿import os

# 获得目录下的所有文件（不包含文件夹）
def get_path_filename(path,suffix,ignore):
    l = []
    l2 = []                             # 处理后的列表
    def VisitDir(arg, dirname, names):
        for filespath in names:
            row =os.path.join(dirname, filespath)
            l.append(row)

    path="."
    abs_path= os.getcwd()
    os.path.walk(abs_path, VisitDir, ())

    for each in l:
        if suffix in each and not ignore in each :
           l2.append(each) 
    return l2


def merge_file(l):
    file = open('result.txt','w')
    #先遍历文件名  
    for filepath in l:  
        #遍历单个文件，读取行数
        file.writelines('##>>>>>>>'+filepath.split('\\')[-1]+"<<<<<<<\n")
        for line in open(filepath):
            file.writelines(line)  
        file.write('\n\n')  
      
    #关闭文件  
    file.close() 

if __name__=="__main__":
    l = get_path_filename('.','.html',ignore='.pyc')
    print '\n'.join(l)
    merge_file(l)
 
        

